package com.ysd.order.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ysd.common.entity.Orders;
import com.ysd.common.entity.Product;
import com.ysd.common.utils.OrdersVo;
import com.ysd.order.service.OrdersService;

@Controller
@RequestMapping("/order")
public class OrdersController {

	@Autowired
	public OrdersService service;

	/**
	 * 查询所有订单信息
	 * 测试路径：http://localhost:88/shop-service-order/order/showAll?page=1&limit=10&state=&fUid=1&name=&phone=
	 * @param ordersVo 为了分页+条件查询创建的辅助实体类
	 * @param page jsp传过来的分页参数（第几页）
	 * @param limit jsp传过来的分页参数（每页显示多少条）
	 * @return layui数据表格的json格式
	 */
	@RequestMapping("/showAll")
	@ResponseBody
	public Map<String, Object> showAll(OrdersVo ordersVo,int page,int limit) {
		Map<String, Object> map = service.showAllInfo(ordersVo, page, limit);
		return map;
	}

	/**
	 * 根据订单的编号，修改订单的基本信息
	 * @param orders 前台传过来的参数以对象的方式进行存储
	 * @return
	 */
	@RequestMapping("/update")
	@ResponseBody
	public boolean update(Orders orders) {
		int num = service.update(orders);
		return num > 0 ? true : false;
	}

	/**
	 * 修改订单的状态（待发货-》待收货）
	 * @param id 订单的编号
	 * @return
	 */
	@RequestMapping("/updateFH")
	@ResponseBody
	public boolean updateFH(int id) {
		int num = service.updateFH(id);
		return num > 0 ? true : false;
	}
	/**
	 * 创建一个新订单
	 * 测试路径：http://localhost:88/shop-service-order/order/insert?fUid=1&money=200&name=admin&phone=123456789&province=河南&city=洛阳&area=老城&addressinfo=哈哈&fPid=4&price=50&num=4&size=iphone&mark=快点发货&ext1=订单详情的json字符串
	 * 订单详情的JSON字符串test： [{"id":"4","name":"华为p40","f_pcid":"4","oldprice":"4988","newprice":"4188","plate":"华为","size":"166*166*14","cate":"智能","factory":"深圳","area":"深圳","description":"超大电池","imgzt":"picture/p1.jpg","isxj":"1","isdel":"0","weight":"1","isxss":"0","isxsg":"0","ext1":"-1","ext2":"-1","ext3":"-1","ext4":"-1","ext5":"-1","ext6":"-1"},{"id":"4","name":"华为p40","f_pcid":"4","oldprice":"4988","newprice":"4188","plate":"华为","size":"166*166*14","cate":"智能","factory":"深圳","area":"深圳","description":"超大电池","imgzt":"picture/p1.jpg","isxj":"1","isdel":"0","weight":"1","isxss":"0","isxsg":"0","ext1":"-1","ext2":"-1","ext3":"-1","ext4":"-1","ext5":"-1","ext6":"-1"}]
	 * @param orders 一个订单对象
	 * @return
	 */
	@RequestMapping("/insert")
	@ResponseBody
	public boolean insert(Orders orders) {
		int num = service.insert(orders);
		return num > 0 ? true : false;
	}

	/**
	 * 删除订单（前台用户在付款前可以取消订单）
	 * 测试路径：http://localhost:88/shop-service-order/order/delete?id=14
	 * @param id 订单的编号
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public boolean delete(int id) {
		int num = service.delete(id);
		return num > 0 ? true : false;
	}
	
	/**
	 * 根据订单的编号进行订单详情（这个订单下的哪些商品）的查询
	 * @param id
	 * @return
	 */
	@RequestMapping("/showInfoById")
	@ResponseBody
	public Map<String,Object> showInfoById(int id){
		Map<String,Object> map = service.showInfoById(id);
		return map;
	}
	
	/**
	 * 查询最近七天的订单成交金额
	 * 测试路径：http://localhost:88/shop-service-order/order/showAllByFuKuanTime
	 */
	@RequestMapping("/showAllByFuKuanTime")
	@ResponseBody
	public Map<String,Object> showAllByFuKuanTime(){
		Map<String,Object> map = service.showAllByFuKuanTime();
		return map;
	}
	
	/**
	 * 修改订单的状态（待付款-》待发货）
	 * @param id 订单的编号
	 * @return
	 */
	@RequestMapping("/updateFK")
	@ResponseBody
	public boolean updateFK(int id) {
		int num = service.updateFK(id);
		return num > 0 ? true : false;
	}
	
	
	/*
	 * @Autowired private ProductDemoFeginClient productFeginClient;
	 */

	
	/**
	 * 下订单功能，调用产品微服务
	 * 
	 * Feign可帮助我们更加便捷，优雅的调用HTTP API。
	 * 在SpringCloud中，使用Feign非常简单——创建一个接口，并在接口上添加一些注解，代码就完成了。
	 * <p/>
	 *
	 * Feign内部已整合了Ribbon和Hystrix，所以只要使用了Feign，另外2个无须引入，可配置开启直接使用。
	 *
	 * @return Product
	 */
	/*
	 * @GetMapping("/buy/{id}") public ProductDemo order(@PathVariable Long id) {
	 * return productFeginClient.findById(id); }
	 */
}
